var  params={};
var deparmentId;
$(function () {
    initDataGrid();
})


function query(){
    debugger;
    var params = $('#table').datagrid('options').queryParams; //先取得 datagrid 的查询参数
    var fields =$('#searchFrom').serializeArray(); //自动序列化表单元素为JSON对象
    $.each( fields, function(i, field){
        params[field.name] = field.value; //设置查询参数
    });
    $('#table').datagrid('reload'); //设置好查询参数 reload
}

function reset() {
    $("#searchFrom").form('clear');
    $("input[name='departmentId']").val(deparmentId)
    query();
}


function  initDataGrid() {
    $("#processOwn").datagrid({
        toolbar:"#processOwn_tb",
        pagination:true,
        rownumbers:true,
        checkOnSelect:true,
        url:"/processOwn/pageList",
        striped:true,
        frozenColumns:[[{
            field:"id",
            checkbox:true
        }]],
        columns:[[
            {field:'processName',title:'申请单名称',width:'30%',align:'center'},
            {field:'userName',title:'申请人',width:'10%',align:'center',},
            {field:'status',title:'当前状态',width:'10%',align:'center',
                formatter:function (value,row,index) {
                    if(value==1){
                        return "未启动";
                    }else if(value==2){
                        return "正在审批";
                    }else if(value==3){
                        return "审核通过";
                    }else if(value==4) {
                        return "审核不通过";
                    }
                }
            },
            {field:'auditorName',title:'当前审核人',width:'10%',align:'center'},
            {field:'createTime',title:'申请时间',width:'20%',align:'center',formatter:formatDate}
        ]]
    })
}
/**
 * 隐藏部分手机号码
 * @param value
 * @returns {string | void}
 */
function  exchangeTel(value) {
    return value.replace(/(\d{3})(\d{4})(\d{4})/,"$1****$3");
}



/**
 * 删除用户
 */
function deleteUser() {
    deleteData("table","用户","user/delete");
}

function add() {
    $('#processOwn_add_dialog').dialog({
        title: '新建流程',
        width: 450,
        height: 250,
        closed: false,
        cache: false,
        href: 'base/toPage?path=activity/processOwn_add',
        modal: true
    });
}

